package top.api.controller;


import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.api.Constants.SystemConstants;
import top.api.common.ResponseResult;
import top.api.domain.entity.Comment;
import top.api.service.CommentService;

@RestController
@RequestMapping("/comment")
@Api(tags = "评论")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @GetMapping("/commentList")
    @ApiOperation("获取文章评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleId", value = "文章ID",required = true)
    })
    public ResponseResult commentList(@RequestParam Long articleId, @RequestParam Integer pageNum, @RequestParam Integer pageSize){
        return commentService.commentList(SystemConstants.ARTICLE_COMMENT,articleId, pageNum, pageSize);
    }

    @GetMapping("/linkCommentList")
    @ApiOperation("获取友链评论")
    public ResponseResult linkCommentList(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        return commentService.commentList(SystemConstants.LINK_COMMENT,null,pageNum,pageSize);
    }

    /**
     * 添加评论
     * type: 文章: 0  友链: 1
     * {"articleId":1,"type":0,"rootId":-1,"toCommentId":-1,"toCommentUserId":-1,"content":"评论内容"}
     * @param comment
     * @return
     */
    @PostMapping
    @ApiOperation(value = "添加评论")
    public ResponseResult addComment(@RequestBody Comment comment){
        return commentService.addComment(comment);
    }

}
